using System;

namespace hemsidan.Entities
{
	/// <summary>
	/// Summary description for PageText.
	/// </summary>
	public class PageText
	{
		public PageText()
		{

		}

		public static System.Data.DataTable GetAll()
		{
			string sql = "select * from PageText";
			System.Data.DataSet ds = DataAccess.DB.getInstance().ExecuteDataSet(sql);
			return ds.Tables[0];
		}

		public static System.Data.DataTable GetPageText(string PageName)
		{
			string sql = "select * from PageText where PageName='" + PageName + "'";
			DataAccess.DB db = DataAccess.DB.getInstance();
            System.Data.DataSet ds = db.ExecuteDataSet(sql);
            return ds.Tables[0];
		}
		public static void CreatePageText(string PageName, string Header, string TextField)
		{
			TextField = PrepText(TextField);
			string sql = "insert into PageText (Header, TextField, PageName) values ('" + Header + "', '" + TextField + "', '" + PageName + "')";
			DataAccess.DB.getInstance().ExecuteNonQuery(sql);
		}

		public static void UpdatePageText(int PageId, string PageName, string Header, string TextField)
		{
			TextField = PrepText(TextField);
			string sql = "update PageText set Header='" + Header + "',PageName='" + PageName + "', TextField='" + TextField + "' where Id=" + PageId;
			DataAccess.DB.getInstance().ExecuteNonQuery(sql);
		}

		public static void DeletePageText(int PageId)
		{
			string sql = "delete from PageText where Id=" + PageId.ToString();
			DataAccess.DB.getInstance().ExecuteNonQuery(sql);
		}

		private static string PrepText(string TextField)
		{
			TextField = TextField.Replace("\n","<br>");
			return TextField;
		}
	}
}
